package com.jxufe.weather;

import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class WeaMapper extends Mapper<Object, Text, Text, WeaBean> {
	
	@Override
	protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
		String line = value.toString();
		String[] fileds = line.split(" ");
		int cityid =Integer.parseInt( fileds[0]);
		int week =Integer.parseInt( fileds[2]);
//		String city = fileds[1];
		double tem1 = temToDouble(fileds[11]);
		double tem2 = temToDouble(fileds[12]);
		double tem = temToDouble(fileds[13]);
		WeaBean weaBean = new WeaBean(cityid, week, tem1, tem2, tem);
//		if(1 == 1) {
//			throw new RuntimeException(weaBean.toString());
//		}
		context.write(new Text(cityid+""), weaBean);
	}
	private Double temToDouble(String tem) {
		String trimTem = tem.substring(0,tem.length()-1);
		return Double.parseDouble(trimTem);
	}

}
